package com.mtsmda.java.json.jsonGson;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.util.ArrayList;
import java.util.List;

import com.google.gson.Gson;
import com.mtsmda.Country;
import com.mtsmda.State;

public class WriteToFileJSONGSON {

	public static void main(String[] args) throws Exception {
		Country country = new Country();
		country.setCountryName("Moldova");
		country.setCountryPopulation(new Double(3_500_000));
		List<State> states = new ArrayList<>();
		states.add(new State("Komrat", new Long(100_000)));
		states.add(new State("Vulkanesty", new Long(18_500)));
		country.setStates(states);

		Gson gson = new Gson();
		String json = gson.toJson(country);
		System.out.println(json);
		File fileJSON_GSON = new File("countriesJSON_GSON.json");
		if (!fileJSON_GSON.exists()) {
			fileJSON_GSON.createNewFile();
		}

		Writer writer = new FileWriter(fileJSON_GSON);
		writer.write(json);
		writer.close();

	}

}